

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:yybb_flutter/Macros/yyb_macros.dart';
import 'package:yybb_flutter/http/http_utils.dart';
import 'package:yybb_flutter/http/api_response.dart';
import 'package:yybb_flutter/modules/abnormal_order/apiservise/order_api_servise.dart';
import 'package:yybb_flutter/modules/abnormal_order/models/yybb_abnomal_order_detail_model.dart';
import 'package:yybb_flutter/modules/abnormal_order/models/yybb_abnormal_order_model.dart';
import 'package:yybb_flutter/yybbtools/yybb_services.dart';


class AbnormalOrderVModel {


  static Future<ApiResponse<YYBBAbnormalOrderModelResultData>> getCategories(Map param) async {
    try {
      final response = await HttpUtils.get(
        categories,
        params:param,
      );
      Map dataMap = response;
      YYBBAbnormalOrderModelResultData data =  YYBBAbnormalOrderModelResultData.fromJson(dataMap["resultData"]);
      return ApiResponse.completed(data);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }

  }

  static Future <ApiResponse<YYBBAbnormalOrderDetailModel>>getOrderDetailData(Map param) async {
    final String abnormalType = param["abnormalType"];
    String urlStr = "/order/buyer/order/product_detail/${param["orderID"]}";
    try {
      final response = await  HttpUtils.get(
        urlStr,
        params:param,
      );
      Map dataMap = response;
      YYBBAbnormalOrderDetailModel item = YYBBAbnormalOrderDetailModel.fromJson(dataMap["resultData"]);
      return ApiResponse.completed(item);
    }
    on DioError catch (e){
      return ApiResponse.error(e.error);
    }
  }


  String getLinePressInfoWithSpecificationType(YYBBSpecificationType specificationType, YYBBAbnormalOrderModelOrderProduct item){

    var  _linePressInfo = "";
    if (specificationType == YYBBSpecificationType.cardboard) {
    }else {

      // ignore: unrelated_type_equality_checks
      if (item.cuttingMode == YYBBOrderCuttingMode.havePress.index) {
        var lineModeStr = "";
        // ignore: unrelated_type_equality_checks
        if (item.lineMode == YYBBOrderLineMode.bump.index) {
          YYBBPrintLog(YYBBOrderLineMode.bump.index);

          lineModeStr = "凹凸";
        }
        // ignore: unrelated_type_equality_checks
        else if (item.lineMode == YYBBOrderLineMode.flat.index) {
          lineModeStr = "平压";
        }
        // ignore: unrelated_type_equality_checks
        else if (item.lineMode == YYBBOrderLineMode.sharp.index) {
          lineModeStr = "尖尖";
        }

        var lineDepthStr = "";
        // ignore: unrelated_type_equality_checks
        if (item.lineDepth == YYBBOrderLineDepth.common.index) {
          lineDepthStr = "普通";
        }
        // ignore: unrelated_type_equality_checks
        else if (item.lineDepth == YYBBOrderLineDepth.reductionShadow.index) {
          lineDepthStr = "减浅";
        }
        // ignore: unrelated_type_equality_checks
        else if (item.lineDepth == YYBBOrderLineDepth.addDeep.index) {
          lineDepthStr = "加深";
        }
        else {
          lineDepthStr = "";
        }

        if (lineDepthStr != null || lineDepthStr.isNotEmpty ) {
            if(item.lineSize == null  || item.lineSize.isEmpty){return "";}
             _linePressInfo = "${item.lineSize}($lineModeStr/$lineDepthStr)";

        }else{
          if(item.lineSize == null ||  item.lineSize.isEmpty){return "";}
          _linePressInfo = "${item.lineSize}($lineDepthStr)";

        }
      // ignore: unrelated_type_equality_checks
      }
      else if (item.cuttingMode == YYBBOrderCuttingMode.noPress.index)
      {
        _linePressInfo = "净边无压线";
      }
      // ignore: unrelated_type_equality_checks
      else if (item.cuttingMode == YYBBOrderCuttingMode.burrs.index)
      {
        _linePressInfo = "毛边";
      }
      // ignore: unrelated_type_equality_checks
      else if (item.cuttingMode  ==  YYBBOrderCuttingMode.other.index)
      {
        _linePressInfo = "";
      }

    }

    return _linePressInfo;
  }




}
